
from world import world, engine, town
from pygameui import ui, world_display, event, arrow_merchant
import pygame

class MerchantReporter(object):
    def __init__(self, m):
        self.merchant = m
    def do_turn(self, rank):
        print self.merchant

interface = ui.UI()
interface.add_e_handler(event.QuitHandler(interface))


w = world.World()
w.populate()
w.to_all_towns(town.Town.randomize_prices)

simulation = engine.get_simulation()
simulation.world = w

merchant = arrow_merchant.ArrowMerchant(w)
merchant.set_location((0,0))
simulation.add_turn_listener(merchant, engine.EVENTS)
simulation.add_turn_listener(MerchantReporter(merchant), engine.UI)



interface.add_e_handler(merchant.get_end_turn_handler(simulation))

wd = world_display.WorldDisplay(w)

interface.window.set_display(wd)
interface.go()
    
